home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / dc-sx107install / sx / developer / sasc / sx_whof.c < prev    next >
C/C++ Source or Header  |  1999-11-29  |  4KB  |  222 lines

  1. /*
  2.  
  3. SX_WHOF (Who Transfered)
  4.  
  5. */
  6.  
  7. static const char __version[] = "\0$VER: SX_WHOF 1.0 ("__DATE__")";
  8.  
  9. #include <time.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15.  
  16. struct MsgPort *bbsport;
  17.  
  18. struct JHMessage
  19. {
  20.   struct Message Msg;
  21.   char String[200];
  22.   int Data;
  23.   int Command;
  24.   int NodeID;
  25.   int LineNum;
  26.   unsigned long signal;
  27.   struct Process *task;
  28.   APTR *Semi;
  29. } themsg;
  30.  
  31.  
  32. void ShutDown(void);
  33. void PS(char * str);
  34. void XIMFunction(int func, long data, char * str);
  35. void WhoF(void);
  36. void myctime(long secs, char *outbuf);
  37.  
  38.  
  39.  
  40. int main(int argc, char *argv[])
  41. {
  42.     char portname[16];
  43.  
  44.     if(argv[1][0]==0)
  45.     {
  46.         PutStr("This program requires System-X BBS Software\n");
  47.     } else {
  48.         sprintf(portname, "AEDoorPort%s", argv[1]);
  49.         bbsport = FindPort(portname);
  50.         if(bbsport)
  51.         {
  52.             XIMFunction(1, 0, 0);     /* function 1 = register */
  53.  
  54.             WhoF();
  55.  
  56.             XIMFunction(2, 0, 0);     /* function 2 = shutdown */
  57.         }
  58.     }
  59. }
  60.  
  61. void ShutDown(void)
  62. {
  63.     XIMFunction(2, 0, 0);
  64.     exit(0);
  65. }
  66.  
  67. void PS(char * str)
  68. {
  69.     XIMFunction(1500, (long)str, 0);
  70. }
  71.  
  72. void XIMFunction(int func, long data, char * str)
  73. {
  74.     struct MsgPort *replyport;
  75.  
  76.     replyport = CreateMsgPort();
  77.     if(replyport)
  78.     {
  79.         themsg.Msg.mn_Length    = sizeof(struct JHMessage);
  80.         themsg.Msg.mn_ReplyPort    = replyport;
  81.         themsg.Data         = data;
  82.         themsg.Command         = func;
  83.         if(str && str[0]!=0) strcpy(themsg.String, str);
  84.         PutMsg(bbsport, (struct Message *)&themsg);
  85.         WaitPort(replyport);
  86.         DeleteMsgPort(replyport);
  87.     }
  88. }
  89.  
  90. void WhoF(void)
  91. {
  92.     char buf[256], timestr[32], filename[36], *arg;
  93.     BPTR fh, fhup, fhdn;
  94.     struct XferLog
  95.     {
  96.         UWORD    user_slot;
  97.         UBYTE    conf,
  98.             filearea;
  99.         char    filename[32];
  100.         long    size,
  101.             baud,
  102.             cps,
  103.             time;
  104.         UBYTE    node;
  105.         char    res[7];
  106.     } Xfer;
  107.     struct UserIndexStruct
  108.     {
  109.         char handle[31];
  110.         char realname[31];
  111.         UWORD misc;
  112.     } Index;
  113.     BOOL readfin = FALSE, found = FALSE;
  114.  
  115.     PS("\r\nSystem-X WHOF 1.0 By Zed/DC\r\n\r\n");
  116.  
  117.     XIMFunction(1507, 0, 0);
  118.     arg = (char *)themsg.Data;
  119.     if(arg[0]!=0)
  120.     {
  121.         strcpy(filename, arg);
  122.     } else {
  123.         XIMFunction(5, 34, "Enter filename to search");
  124.         PS("\r\n");
  125.         if(themsg.Data==-1) ShutDown();
  126.         if(themsg.String[0]==0) return;
  127.         strcpy(filename, themsg.String);
  128.     }
  129.  
  130.     fh = Open("SX:User.Index", MODE_OLDFILE);
  131.  
  132.     PS("\r\nSearching for the uploader...\r\n\r\n");
  133.  
  134.     fhup = Open("SX:LogFiles/Upload.LOG", MODE_OLDFILE);
  135.     if(fhup)
  136.     {
  137.         while(!readfin)
  138.         {
  139.             if(Read(fhup, &Xfer, sizeof(struct XferLog)))
  140.             {
  141.                 if(stricmp(Xfer.filename, filename)==0)
  142.                 {
  143.                     readfin = TRUE;
  144.                     found = TRUE;
  145.                 }
  146.             } else {
  147.                 readfin = TRUE;
  148.             }
  149.         }
  150.         Close(fhup);
  151.         if(found)
  152.         {
  153.             Seek(fh, (Xfer.user_slot-1)*sizeof(struct UserIndexStruct), OFFSET_BEGINING);
  154.             Read(fh, &Index, sizeof(struct UserIndexStruct));
  155.  
  156.             myctime(Xfer.time, timestr);
  157.             sprintf(buf, "%-28s %-16s %9ld %s\r\n", Index.handle, Xfer.filename, Xfer.size, timestr);
  158.             PS(buf);
  159.         } else {
  160.             PS("No Uploader found...\r\n");
  161.         }
  162.     } else {
  163.         PS("No Uploader found...\r\n");
  164.     }
  165.  
  166.  
  167.     PS("\r\nSearching for downloaders...\r\n\r\n");
  168.  
  169.     fhdn = Open("SX:LogFiles/Download.LOG", MODE_OLDFILE);
  170.     if(fhdn)
  171.     {
  172.         readfin = FALSE;
  173.         found = FALSE;
  174.         while(!readfin)
  175.         {
  176.             if(Read(fhdn, &Xfer, sizeof(struct XferLog)))
  177.             {
  178.                 if(stricmp(Xfer.filename, filename)==0)
  179.                 {
  180.                     found = TRUE;
  181.  
  182.                     Seek(fh, (Xfer.user_slot-1)*sizeof(struct UserIndexStruct), OFFSET_BEGINING);
  183.                     Read(fh, &Index, sizeof(struct UserIndexStruct));
  184.  
  185.                     myctime(Xfer.time, timestr);
  186.                     sprintf(buf, "%-28s %-16s %9ld %s\r\n", Index.handle, Xfer.filename, Xfer.size, timestr);
  187.                     PS(buf);
  188.                 }
  189.             } else {
  190.                 readfin = TRUE;
  191.             }
  192.         }
  193.         Close(fhdn);
  194.         if(!found) PS("No downloaders found...");
  195.     } else {
  196.         PS("No downloaders found...");
  197.     }
  198.  
  199.     Close(fh);
  200.  
  201.     PS("\r\n\r\n");
  202. }
  203.  
  204. void myctime(long secs, char *outbuf)
  205. {
  206.     struct DateStamp *tp;
  207.     struct DateTime tostr;
  208.  
  209.     tp = __timecvt((time_t)secs);
  210.  
  211.     memcpy(&tostr, tp, 12);
  212.  
  213.     tostr.dat_Format  = FORMAT_USA;
  214.     tostr.dat_StrDay  = "2222222222";
  215.     tostr.dat_StrDate = "000000000";
  216.     tostr.dat_StrTime = "111111111";
  217.     tostr.dat_Flags   = 0;
  218.  
  219.     DateToStr(&tostr);
  220.     sprintf(outbuf, "%s %s", tostr.dat_StrTime, tostr.dat_StrDate);
  221. }
  222.